package o2o.service.sys;

import com.jinyou.utils.common.DateUtils;
import com.jinyou.utils.common.ValidateUtil;
import o2o.cache.shop.ShopMemory;
import o2o.config.dao.UserDaoSql;
import o2o.dao.PO.PojoTables;
import o2o.dao.PO.shop.SHOP_IS_INTEGRAL;
import o2o.company.model.ShopInfo;

import java.sql.SQLException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 */
public class SysSettingService {

    private SysSettingService() {
    }

    enum Singleton {
        INSTANCE;
        private SysSettingService single;

        private Singleton() {
            single = new SysSettingService();
        }

        private SysSettingService getInstance() {
            return single;
        }
    }

    public static SysSettingService getInstance() {
        return Singleton.INSTANCE.single;
    }


    // 添加一个
    public void createIntegerShop() throws SQLException {
        List<ShopInfo> shopInfoList = ShopMemory.getInstance().listOfIntegralShop(SHOP_IS_INTEGRAL.HAS_INTEGRAL_SHOP);
        if (ValidateUtil.isAbsList(shopInfoList)) {
            return;
        }
        Long cTime = DateUtils.getCurrTime();
        // 创建一个默认的积分商城
        ShopInfo info = new ShopInfo();
        info.setDelFlag(0);
        info.setShopName("积分商城");
        info.setOwnName("plate_admin");
        info.setIsIntegralShop(1);
        info.setCreateTime(cTime);
        info.setCreateUser("plate-admin");
        info.setLat(0.00d);
        info.setLng(0.00d);
        try {
            UserDaoSql.getInstance().saveObj(PojoTables.ShopInfo, info);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        ShopMemory.getInstance().add(cTime);
    }

}
